const util = require('../../utils/util.js');
const api = require('../../config/api.js');
const user = require('../../services/user.js');
const pay = require('../../services/pay.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderDetails:{},
    number:'',
    orderId:'',
    retail_price:'',
    buyType:''//购买方式，参团/发起拼团 或者是单独购买，此参数判断支付后的跳转
  },

  pay:function(){
    var _this = this

      pay.payOrder(parseInt(_this.data.orderId)).then(res => {
          if(_this.data.buyType === 'group'){
            wx.redirectTo({
              url: '/pages/success/success?orderId=' + _this.data.orderId,
            })
          }else if(_this.data.buyType === 'self'){
            wx.redirectTo({
              url: '/pages/check/check?orderId='+_this.data.orderId,
            })
          }
      })
    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var _this = this
    var _from = options.from
      _this.setData({ 
        // goodsDetails: JSON.parse(wx.getStorageSync('goodsDetails')),
        // number:options.number,
        // orderId:options.orderId,
        // retail_price: parseInt(options.number) * JSON.parse(wx.getStorageSync('goodsDetails')).info.retail_price,
        orderId: options.orderId,
        buyType: options.buyType
      })
    util.request(api.orderDetails,{orderId:options.orderId}).then((res)=>{
      if(res.errno == 0){
        _this.setData({orderDetails:res.data})
      }else{
        util.showErrorToast(res.msg)
      }
    })
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})